package com.ttbj.core.util;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

public class RandomIdUtil {
    private static AtomicInteger counter = new AtomicInteger(0);

    /**
     * 获取随机数字
     *
     * @return
     * @date 2017年3月21日 下午5:09:34
     */
    public static String getRandomNumber() {
        if (counter.get() > 999999) {
            counter.set(1);
        }
        long time = System.currentTimeMillis();
        long returnValue = time * 100 + counter.incrementAndGet();
        String randomNumber = String.valueOf(returnValue);
        return randomNumber;
    }

    public static String getUUIDCode() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
	/**
	 * 获取随机数+code
	 * 
	 * @date 2017年3月21日 下午5:09:21
	 * 
	 * @return
	 */
	public static String getRandomCode() {
		if (counter.get() > 999999) {
			counter.set(1);
		}
		long time = System.currentTimeMillis();
		long returnValue = time * 100 + counter.incrementAndGet();
		String randomNumber = String.valueOf(returnValue);
		String code = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 4);
		return randomNumber + "_" + code;
	}
}
